package algorithm.bestFirstSearch_4Q;

import java.awt.Point;
import java.util.ArrayList;

public class Diagonal {
	public static ArrayList<ArrayList<Point>> generateDiagonal(int n) {
		ArrayList<ArrayList<Point>> lists = new ArrayList<ArrayList<Point>>();
		Point p = new Point();
		p.y = n - 1;
		p.x = 0;

		ArrayList<Point> list = new ArrayList<Point>();
		list.add(p);
		lists.add(list);

		loop: while (true) {
			ArrayList<Point> gen = generatePoints(list);
			lists.add(gen);
			for (Point tmp : gen)
				if (tmp.y == tmp.x)
					break loop;
			list = gen;
		}

		return lists;
	}

	public static ArrayList<Point> generatePoints(ArrayList<Point> points) {
		ArrayList<Point> array = new ArrayList<Point>();

		Point p = new Point();
		p.y = points.get(0).y - 1;
		p.x = points.get(0).x;
		array.add(p);

		for (int i = 0; i < points.size(); i++) {
			p = new Point();
			p.y = points.get(i).y;
			p.x = points.get(i).x + 1;
			array.add(p);
		}
		return array;
	}
}
